package com.qms.qep.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.qms.common.annotation.Log;
import com.qms.common.core.controller.BaseController;
import com.qms.common.core.domain.AjaxResult;
import com.qms.common.enums.BusinessType;
import com.qms.common.utils.poi.ExcelUtil;
import com.qms.qep.domain.ProcessParam;
import com.qms.qep.service.IProcessParamService;

/**
 * 工序参数Controller
 * 
 * @author qep
 */
@RestController
@RequestMapping("/qep/processParam")
public class ProcessParamController extends BaseController
{
    @Autowired
    private IProcessParamService processParamService;

    /**
     * 查询工序参数列表
     */
    @PreAuthorize("@ss.hasPermi('qep:processParam:list')")
    @GetMapping("/list")
    public AjaxResult list(ProcessParam processParam)
    {
        List<ProcessParam> list = processParamService.selectProcessParamList(processParam);
        return success(list);
    }

    /**
     * 查询工序下的参数列表
     */
    @PreAuthorize("@ss.hasPermi('qep:processParam:list')")
    @GetMapping("/process/{processId}")
    public AjaxResult listByProcessId(@PathVariable("processId") Long processId)
    {
        List<ProcessParam> list = processParamService.selectProcessParamsByProcessId(processId);
        return success(list);
    }

    /**
     * 获取工序参数详细信息
     */
    @PreAuthorize("@ss.hasPermi('qep:processParam:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(processParamService.selectProcessParamById(id));
    }

    /**
     * 新增工序参数
     */
    @PreAuthorize("@ss.hasPermi('qep:processParam:add')")
    @Log(title = "工序参数", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProcessParam processParam)
    {
        return toAjax(processParamService.insertProcessParam(processParam));
    }

    /**
     * 修改工序参数
     */
    @PreAuthorize("@ss.hasPermi('qep:processParam:edit')")
    @Log(title = "工序参数", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProcessParam processParam)
    {
        return toAjax(processParamService.updateProcessParam(processParam));
    }

    /**
     * 删除工序参数
     */
    @PreAuthorize("@ss.hasPermi('qep:processParam:remove')")
    @Log(title = "工序参数", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Long id)
    {
        return toAjax(processParamService.deleteProcessParamById(id));
    }
    
    /**
     * 批量删除工序参数
     */
    @PreAuthorize("@ss.hasPermi('qep:processParam:remove')")
    @Log(title = "工序参数", businessType = BusinessType.DELETE)
    @DeleteMapping("/batch/{ids}")
    public AjaxResult batchRemove(@PathVariable String ids)
    {
        Long[] paramIds = convert(ids);
        return toAjax(processParamService.deleteProcessParamByIds(paramIds));
    }
    
    /**
     * 将字符串ID转换为Long数组
     */
    private Long[] convert(String ids)
    {
        String[] idArray = ids.split(",");
        Long[] result = new Long[idArray.length];
        for (int i = 0; i < idArray.length; i++)
        {
            result[i] = Long.valueOf(idArray[i]);
        }
        return result;
    }
} 